import axios from 'axios'
// 异步get
function fetchGet(url, params) {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            axios.get(url, params)
                .then(Response => {
                    //  console.log('api-ok')
                    resolve(Response.data)
                })
                .catch(error => {
                    //  console.log(error)
                    reject(error)
                })
        }, 0)
    })
}
// 异步post
function fetchPost(url, params) {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            axios.post(url, params, {
                headers: {
                    'Content-Type': 'application/json'
                }
            })
                .then(res => {
                    console.log('api-ok')
                    resolve(res)
                })
                .catch(error => {
                    console.log(error)
                    reject(error)
                })
        }, 0)
    })
}

// 异步post文件上传
function fetchUpLoad(url, params) {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            axios.post(url, params, {})
                .then(res => {
                    console.log('api-ok')
                    resolve(res)
                })
                .catch(error => {
                    console.log(error)
                    reject(error)
                })
        }, 0)
    })
}

export default {
  /**
   * GET 方法
   */
    mineBaseMsgApi(url) {
        console.log('进入getapi.js')
        return fetchGet(url)
    },
  /**
   * post 方法
   */
    minePostMsgApi(url, params) {
        console.log('进入postapi.js')
        return fetchPost(url, params)
    },
  /**
   * 文件post 方法
   */
    mineUpLoadMsgApi(url, params) {
        console.log('进入uploadapi.js')
        return fetchUpLoad(url, params)
    }
}
